package org.example.com.controller;

import jakarta.annotation.Resource;
import org.example.com.Bean.Category;
import org.example.com.Bean.User;
import org.example.com.service.CategoryService;
import org.example.com.util.JsonResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class categoryController {
    @Resource
    private CategoryService categoryService;
    @GetMapping
   public JsonResult getCategory() {
        return categoryService.findCategory();
    }
    @GetMapping("/page/{page}")
    public JsonResult find(@PathVariable("page") int page) {
        return categoryService.findCategory(page);
    }
    @PostMapping
    public JsonResult save(Category category) {
        return categoryService.saveCategory(category);
    }
    @PutMapping
    public JsonResult update(Category category) {
        return categoryService.updateCategory(category);
    }
    @PutMapping("/change_status/{id}/{status}")
    public JsonResult update(@PathVariable("id") String id,@PathVariable("status") int status){
        return categoryService.updateCategoryStatus(id,status);
    }
    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable("id") String id){
        return categoryService.deleteCategory(id);
    }
}
